package com.gxa.saas.controller;


import com.gxa.saas.mapper.SalemanMapper;
import com.gxa.saas.pojo.SaleGoods;
import com.gxa.saas.pojo.SaleStores;
import com.gxa.saas.pojo.Saleman;

import com.gxa.saas.service.SaleGoodsService;
import com.gxa.saas.service.SalemanService;
import com.gxa.saas.service.SalestoresService;
import com.gxa.saas.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@Api()
@RestController
@CrossOrigin
@RequestMapping("/sale")
public class SaleController {

    @Autowired
    SalemanService salemanService;

    @Autowired
    SalemanMapper salemanMapper;
    @Autowired
    SalestoresService salestoresService;

    @Autowired
    SaleGoodsService saleGoodsService;

    @ApiOperation(value = "人员销售分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name= "page",value = "页码",paramType = "int",dataType = "query"),
            @ApiImplicitParam(name= "size",value = "每页大小",paramType = "int",dataType = "query")
    })

    @PostMapping("/selectByPage")
    public Map selectByPage(Integer page, Integer size){
        System.out.println(page);
        System.out.println(size);
        List<Saleman> salemen = salemanService.selectAll();
        List<Saleman> salemen1 = salemanService.selectByPage(page, size);

        JsonResult jsonResult=new JsonResult();
        jsonResult.setData(salemen1);
        jsonResult.setCode("200");
        jsonResult.set("total",salemen1.size());

        return jsonResult.getMap();
    }
    @ApiOperation(value = "人员销售查询本日",produces ="query")
    @PostMapping("/selectByTime")
    public Map selectByTime(String time){
    time = time.replace("/", "-").substring(0, 10);

        List<Saleman> salemen = salemanService.selectByTime(time);

        JsonResult jsonResult=new JsonResult();
        jsonResult.setData(salemen);
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }

    @ApiOperation(value = "门店销售分页查询",produces ="query")
    @PostMapping("/selectByPage2")
    public Map selectByPage2(Integer page,Integer size){
        List<SaleStores> saleStores1 = salestoresService.selectAll();
        List<SaleStores> saleStores = salestoresService.selectByPage(page, size);


        JsonResult jsonResult=new JsonResult();
        jsonResult.setData(saleStores);
        jsonResult.setCode("200");
        jsonResult.set("total",saleStores1.size());
         return  jsonResult.getMap();
    }
    @ApiOperation(value = "门店销售查询本日",produces ="query")
    @PostMapping("/selectByTime2")
    public Map selectByTime2(String time){
        time = time.replace("/", "-").substring(0, 10);

        List<SaleStores> saleStores = salestoresService.selectByTime(time);

        JsonResult jsonResult=new JsonResult();
        jsonResult.setData(saleStores);
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }
    @ApiOperation(value = "商品销售分页查询",produces ="query")
    @PostMapping("/selectByPage3")
    public Map selectByPage3(Integer page,Integer size){
        List<SaleGoods> saleGoods = saleGoodsService.selectAll();
        List<SaleGoods> saleGoods1 = saleGoodsService.selectByPage(page, size);

        JsonResult jsonResult=new JsonResult();
        jsonResult.setData(saleGoods1);
        jsonResult.setCode("200");
        jsonResult.set("total",saleGoods.size());
        return  jsonResult.getMap();
    }
    @ApiOperation(value = "商品销售查询本日",produces ="query")
    @PostMapping("/selectByTime3")
    public Map selectByTime3(String time){
        time = time.replace("/", "-").substring(0, 10);
        List<SaleGoods> saleGoods = saleGoodsService.selectByTime(time);

        JsonResult jsonResult=new JsonResult();
        jsonResult.setData(saleGoods);
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }

}
